package com.itheima.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 请求转发实例
 * 实现request对象实现资源间数据的共享
 * 数据是以键值对的方式存放
 */

@WebServlet("/RequestDemo7")
public class RequestDemo7 extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("RequestDemo7...");
        //在转发的时候使用request对象实现资源间数据的共享
        //使用setAttribute方法存放一个键值对数据，在请求转发的时候就会被传给下一个资源
        request.setAttribute("msg","hello");

        //请求转发的时候要把已经处理好的数据带给另一个资源（servlet），所以需要传入request和response参数
        request.getRequestDispatcher("/RequestDemo8").forward(request,response);



    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}